<?php


namespace app\home\model\page\shop;


use app\api\model\dao\FlashSale;
use app\library\Error;
use app\library\PageBase;

class DeleteFlashSale extends PageBase
{
    private $objFlashSaleModel;

    public function __construct()
    {
        parent::__construct();
        $this->objFlashSaleModel = new FlashSale();
    }

    public function excute($param)
    {
        $ret = $this->checkToken($param);
        if (false === $ret) {
            return $this->getRes(Error::ERR_NO_AUTH);
        }

        $ret = $this->checkParam($param);
        if ($ret) {
            return $this->getRes(Error::ERR_PARAM, $ret);
        }

        $ret = $this->objFlashSaleModel->editFlashSale($param);
        if (false === $ret) {
            return $this->getRes(Error::ERR_SYS);
        }
        return $this->getRes();
    }


    public function checkParam($param)
    {
        $rule = [
            'id' => 'require',
        ];
        $msg = [
            'id.require' => 'ID必须',
        ];
        $validate = new \think\Validate($rule, $msg);
        $result = $validate->check($param);
        if (!$result) {
            return $validate->getError();
        }
        return '';
    }
}